﻿<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>
  
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Exceptions in ETL process </title>
    <meta name="viewport" content="width=device-width">
    <meta name="title" content="Exceptions in ETL process ">
    <meta name="generator" content="docfx 2.40.1.0">
    
    <link rel="shortcut icon" href="../favicon.ico">
    <link rel="stylesheet" href="../styles/docfx.vendor.css">
    <link rel="stylesheet" href="../styles/docfx.css">
    <link rel="stylesheet" href="../styles/main.css">
    <meta property="docfx:navrel" content="../toc.html">
    <meta property="docfx:tocrel" content="toc.html">
    
    
    
  </head>
  <body data-spy="scroll" data-target="#affix" data-offset="120">
    <div id="wrapper">
      <header>
        
        <nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation">
          <div class="container">
            <div class="navbar-header">
              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
              </button>
              
              <a class="navbar-brand" href="../index.html">
                <img id="logo" class="svg" src="../images/logo.svg" alt="">
              </a>
            </div>
            <div class="collapse navbar-collapse" id="navbar">
              <form class="navbar-form navbar-right" role="search" id="search">
                <div class="form-group">
                  <input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
                </div>
              </form>
              <a class="navbar-brand" href="https://github.com/paillave/Etl.Net" style="float:right">
                <img id="logo" class="svg" src="../images/github.svg" style="height:52px">
              </a>
            </div>
          </div>
        </nav>
        
        <div class="subnav navbar navbar-default">
          <div class="container hide-when-search" id="breadcrumb">
            <ul class="breadcrumb">
              <li></li>
            </ul>
          </div>
        </div>
      </header>
      <div role="main" class="container body-content hide-when-search">
        
        <div class="sidenav hide-when-search">
          <a class="btn toc-toggle collapse" data-toggle="collapse" href="#sidetoggle" aria-expanded="false" aria-controls="sidetoggle">Show / Hide Table of Contents</a>
          <div class="sidetoggle collapse" id="sidetoggle">
            <div id="sidetoc"></div>
          </div>
        </div>
        <div class="article row grid-right">
          <div class="col-md-10">
            <article class="content wrap" id="_content" data-uid="">
<h1 id="exceptions-in-etl-process">Exceptions in ETL process</h1>

<h2 id="types-of-calls">Types of calls</h2>
<p>Even if there are several ways to run an ETL process, there are two categories of calls:</p>
<ul>
<li>The call that will raise an exception if something in the job fails. The calls that are described the recipe <a href="Execute.Etl.Process.html#source-code-example">Execute an Etl process</a> correspond to this type</li>
<li>The call that will stop if the job fails. The execution status and the  cause of the problem is into the task result object.</li>
</ul>
<h2 id="trycatch">Try/Catch</h2>
<p>By using <code>ExecuteAsync</code> or <code>CreateAndExecuteAsync</code>, the exception must be caught on the <code>Wait()</code> method of the task. In this case, the expected exception is the regular exception type we get when the underlying process of a task raise an exception: <code>System.AggregateException</code>.
This exception contains an InnerException that has the type <code>Paillave.Etl.Recipes.DefineProcess.SimpleJobThrowException</code>. <code>SimpleJobThrowException</code> gives access to the trace that is at the source of the end of this process. This trace permits to know in which node happened the exception, and possibly witch row when through at this moment. The exception that is the root cause of the problem is in the <code>InnerException</code> of <code>SimpleJobThrowException</code>.</p>
<p>This will run the ETL process defined in the recipe <a href="Define.Etl.Process.html#source-code-example">Define an Etl process</a></p>
<div class="tabGroup" id="tabgroup_CeZOj-G++Q">
<ul role="tablist">
<li role="presentation">
<a href="#tabpanel_CeZOj-G++Q_TryCatchInlineCallExecution" role="tab" aria-controls="tabpanel_CeZOj-G++Q_TryCatchInlineCallExecution" data-tab="TryCatchInlineCallExecution" tabindex="0" aria-selected="true">Inline call execution</a>
</li>
<li role="presentation">
<a href="#tabpanel_CeZOj-G++Q_TryCatchInstanceRunnerCreation" role="tab" aria-controls="tabpanel_CeZOj-G++Q_TryCatchInstanceRunnerCreation" data-tab="TryCatchInstanceRunnerCreation" tabindex="-1">Ask runner instance creation</a>
</li>
<li role="presentation">
<a href="#tabpanel_CeZOj-G++Q_TryCatchCreateRunnerInstance" role="tab" aria-controls="tabpanel_CeZOj-G++Q_TryCatchCreateRunnerInstance" data-tab="TryCatchCreateRunnerInstance" tabindex="-1">Create runner instance</a>
</li>
</ul>
<section id="tabpanel_CeZOj-G++Q_TryCatchInlineCallExecution" role="tabpanel" data-tab="TryCatchInlineCallExecution">
<pre><code class="lang-csharp" name="Main">[TestMethod]
public void InlineMethodWay()
{
    var config = new SimpleConfigStreamType { Divider = 0 };
    var task = StreamProcessRunner.CreateAndExecuteAsync(config, SimpleJob.Job1);
    try
    {
        task.Wait();
        Assert.Fail(&quot;the execution should not be successfull&quot;);
    }
    catch (AggregateException ex)
    {
        JobExecutionException jobExecutionException = ex.InnerException as JobExecutionException;
        if (jobExecutionException == null) throw;
        Assert.IsInstanceOfType(jobExecutionException.InnerException, typeof(DivideByZeroException));
        Assert.IsInstanceOfType((jobExecutionException.TraceEvent?.Content as UnhandledExceptionStreamTraceContent)?.Exception, typeof(DivideByZeroException));
    }
}
</code></pre></section>
<section id="tabpanel_CeZOj-G++Q_TryCatchInstanceRunnerCreation" role="tabpanel" data-tab="TryCatchInstanceRunnerCreation" aria-hidden="true" hidden="hidden">
<pre><code class="lang-csharp" name="Main">[TestMethod]
public void StaticMethodWay()
{
    var runner = StreamProcessRunner.Create&lt;SimpleConfigStreamType&gt;(SimpleJob.Job1);
    var config = new SimpleConfigStreamType { Divider = 0 };
    var task = runner.ExecuteAsync(config);
    try
    {
        task.Wait();
        Assert.Fail(&quot;the execution should not be successfull&quot;);
    }
    catch (AggregateException ex)
    {
        JobExecutionException jobExecutionException = ex.InnerException as JobExecutionException;
        if (jobExecutionException == null) throw;
        Assert.IsInstanceOfType(jobExecutionException.InnerException, typeof(DivideByZeroException));
        Assert.IsInstanceOfType((jobExecutionException.TraceEvent?.Content as UnhandledExceptionStreamTraceContent)?.Exception, typeof(DivideByZeroException));
    }
}
</code></pre></section>
<section id="tabpanel_CeZOj-G++Q_TryCatchCreateRunnerInstance" role="tabpanel" data-tab="TryCatchCreateRunnerInstance" aria-hidden="true" hidden="hidden">
<pre><code class="lang-csharp" name="Main">[TestMethod]
public void InstanceMethodWay()
{
    var runner = new StreamProcessRunner&lt;SimpleConfigStreamType&gt;(SimpleJob.Job1);
    var config = new SimpleConfigStreamType { Divider = 0 };
    var task = runner.ExecuteAsync(config);
    try
    {
        task.Wait();
        Assert.Fail(&quot;the execution should not be successfull&quot;);
    }
    catch (AggregateException ex)
    {
        JobExecutionException jobExecutionException = ex.InnerException as JobExecutionException;
        if (jobExecutionException == null) throw;
        Assert.IsInstanceOfType(jobExecutionException.InnerException, typeof(DivideByZeroException));
        Assert.IsInstanceOfType((jobExecutionException.TraceEvent?.Content as UnhandledExceptionStreamTraceContent)?.Exception, typeof(DivideByZeroException));
    }
}
</code></pre></section>
</div>
<h2 id="getting-the-execution-status">Getting the execution status</h2>
<p>By using <code>ExecuteWithNoFaultAsync</code> or <code>CreateAndExecuteWithNoFaultAsync</code>, the necessary information about the success is returned in the result of type <code>Paillave.Etl.ExecutionStatus</code> of the task. The exception can be found in the object in the property <code>EndOfProcessTraceEvent</code> that should be of type <code>Paillave.Etl.Core.TraceContents.UnhandledExceptionStreamTraceContent</code>.</p>
<p>This will run the ETL process defined in the recipe <a href="Define.Etl.Process.html#source-code-example">Define an Etl process</a></p>
<div class="tabGroup" id="tabgroup_CeZOj-G++Q-1">
<ul role="tablist">
<li role="presentation">
<a href="#tabpanel_CeZOj-G++Q-1_InlineCallExecution" role="tab" aria-controls="tabpanel_CeZOj-G++Q-1_InlineCallExecution" data-tab="InlineCallExecution" tabindex="0" aria-selected="true">Inline call execution</a>
</li>
<li role="presentation">
<a href="#tabpanel_CeZOj-G++Q-1_InstanceRunnerCreation" role="tab" aria-controls="tabpanel_CeZOj-G++Q-1_InstanceRunnerCreation" data-tab="InstanceRunnerCreation" tabindex="-1">Ask runner instance creation</a>
</li>
<li role="presentation">
<a href="#tabpanel_CeZOj-G++Q-1_CreateRunnerInstance" role="tab" aria-controls="tabpanel_CeZOj-G++Q-1_CreateRunnerInstance" data-tab="CreateRunnerInstance" tabindex="-1">Create runner instance</a>
</li>
</ul>
<section id="tabpanel_CeZOj-G++Q-1_InlineCallExecution" role="tabpanel" data-tab="InlineCallExecution">
<pre><code class="lang-csharp" name="Main">[TestMethod]
public void InlineMethodWay()
{
    var config = new SimpleConfigStreamType { Divider = 0 };
    var task = StreamProcessRunner.CreateAndExecuteWithNoFaultAsync(config, SimpleJob.Job1);
    task.Wait();
    Assert.IsTrue(task.Result.Failed, &quot;the execution should not be successfull&quot;);
    Assert.IsInstanceOfType((task.Result.EndOfProcessTraceEvent?.Content as UnhandledExceptionStreamTraceContent)?.Exception, typeof(DivideByZeroException));
}
</code></pre></section>
<section id="tabpanel_CeZOj-G++Q-1_InstanceRunnerCreation" role="tabpanel" data-tab="InstanceRunnerCreation" aria-hidden="true" hidden="hidden">
<pre><code class="lang-csharp" name="Main">[TestMethod]
public void StaticMethodWay()
{
    var runner = StreamProcessRunner.Create&lt;SimpleConfigStreamType&gt;(SimpleJob.Job1);
    var config = new SimpleConfigStreamType { Divider = 0 };
    var task = runner.ExecuteWithNoFaultAsync(config);
    task.Wait();
    Assert.IsTrue(task.Result.Failed, &quot;the execution should not be successfull&quot;);
    Assert.IsInstanceOfType((task.Result.EndOfProcessTraceEvent?.Content as UnhandledExceptionStreamTraceContent)?.Exception, typeof(DivideByZeroException));
}
</code></pre></section>
<section id="tabpanel_CeZOj-G++Q-1_CreateRunnerInstance" role="tabpanel" data-tab="CreateRunnerInstance" aria-hidden="true" hidden="hidden">
<pre><code class="lang-csharp" name="Main">[TestMethod]
public void InstanceMethodWay()
{
    var runner = new StreamProcessRunner&lt;SimpleConfigStreamType&gt;(SimpleJob.Job1);
    var config = new SimpleConfigStreamType { Divider = 0 };
    var task = runner.ExecuteWithNoFaultAsync(config);
    task.Wait();
    Assert.IsTrue(task.Result.Failed, &quot;the execution should not be successfull&quot;);
    Assert.IsInstanceOfType((task.Result.EndOfProcessTraceEvent?.Content as UnhandledExceptionStreamTraceContent)?.Exception, typeof(DivideByZeroException));
}
</code></pre></section>
</div>
</article>
          </div>
          
          <div class="hidden-sm col-md-2" role="complementary">
            <div class="sideaffix">
              <p><img src="../images/full-black-logo.svg" alt="Logo Etl.Net"></p>
              <div class="contribution">
                <ul class="nav">
                  <li>
                    <a href="https://github.com/paillave/Etl.Net/blob/rehandlereactive/docfx_project/recipes/Exception.Etl.Process.md/#L1" class="contribution-link">Improve this Doc</a>
                  </li>
                </ul>
              </div>
              <nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
              <!-- <p><a class="back-to-top" href="#top">Back to top</a><p> -->
              </nav>
            </div>
          </div>
        </div>
      </div>
      
      <footer>
        <div class="grad-bottom"></div>
        <div class="footer">
          <div class="container">
            <span class="pull-right">
              <a href="#top">Back to top</a>
            </span>
            
            <span>Generated by <strong>DocFX</strong></span>
          </div>
        </div>
      </footer>
    </div>
    
    <script type="text/javascript" src="../styles/docfx.vendor.js"></script>
    <script type="text/javascript" src="../styles/docfx.js"></script>
    <script type="text/javascript" src="../styles/main.js"></script>
  </body>
</html>
